import currentOrder from '../component/current-order.mjs';
import pendingOrder from '../component/pending-order.mjs';
import paidOrder from '../component/paid-order.mjs';
import cancelledOrder from '../component/cancelled-order.mjs';
import mainMenu from '../component/main-menu.mjs';
import frequecyOrder from '../component/frequently-food.mjs';


import imlist from '../component/data.mjs';

var app = new Vue({
    el: "#app",
    data: {
        // 控制切换菜单的标志位
        toggleFlag: 'frequently-food',
        // 控制切换订单区的组件    0=current-order 1=pending-order  2=paid  3=cancelled-order
        orderFlag: 'current-order',
        // 用于存取当前订单的数据
        currentList: [],
        list: imlist,
    },
    components: {
        "current-order": currentOrder,
        "pending-order":pendingOrder,
        "paid-order": paidOrder,
        "cancelled-order":cancelledOrder,
        "frequently-food": frequecyOrder,
        "main-menu":mainMenu,
    },
    methods: {
        // 产品的事件函数
        stapleClick() {
            this.toggleFlag = 'frequently-food';
        },
        mainClick() {
            this.toggleFlag = 'main-menu';
        },
        addClick(e) {
            // 先判断数组的长度 如果为空直接push
            if (this.currentList.length < 1) {
                this.currentList.push(e);
            } else {
                // 不为空判断每次加入的商品名称
                let flag = true;
                this.currentList.forEach((item, index) => {

                    if (item.text===e.text) {
                        flag = false;
                        item.nums++;
                    }
                })
                if (flag) {
                    this.currentList.push(e);

                }
            }

            // console.log(flag);
            console.log(this.currentList);
        },
        // 订单的事件函数
        add(index) {
            console.log(index);
            this.currentList[index].nums++;
        },
        sub(index) {
            console.log(index);

            if (this.currentList[index].nums < 2) {
                this.currentList.splice(index, 1);
            } else {
                this.currentList[index].nums--
            }
        },
        del(index) {

            this.currentList.splice(index, 1);
        }
    },

});